package com.seveneight.baijiesteward.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.seveneight.baijiesteward.R;

/**
 * Created by Administrator on 2017/11/11.
 */

public class WindowUtil {

    private static WindowUtil instance;

    public synchronized static WindowUtil getInstance() {
        if (null == instance) {
            synchronized (WindowUtil.class) {
                if (null == instance) {
                    instance = new WindowUtil();
                }
            }
        }
        return instance;
    }

    public void startActivity(Context ctx, Class<?> classs) {
        Intent i = new Intent(ctx, classs);
        ctx.startActivity(i);
    }

    public void startActivity(Context ctx, Class<?> classs, Bundle bundle) {
        Intent i = new Intent(ctx, classs);
        if (bundle != null) {
            i.putExtras(bundle);
        }
        ctx.startActivity(i);
    }

    public void startActivityResult(Activity ctx, Class<?> classs, int requestCode) {
        Intent i = new Intent(ctx, classs);
        ctx.startActivityForResult(i, requestCode);
    }

    /**
     * 只适用于activity
     * @param ctx
     * @param classs
     * @param bundle
     * @param requestCode
     */
    public void startActivityResult(Activity ctx, Class<?> classs, Bundle bundle, int requestCode) {
        Intent i = new Intent(ctx, classs);
        if (bundle != null) {
            i.putExtras(bundle);
        }
        ctx.startActivityForResult(i, requestCode);
    }

    /**
     * 只适用于activity
     * @param context
     * @param tClass
     */
    public void startUpActivity(Activity context, Class<?> tClass) {
        Intent intent = new Intent(context, tClass);
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.activity_open, 0);
    }

}
